package com.zyt.controller;

import com.github.pagehelper.PageInfo;
import com.zyt.pojo.Category;
import com.zyt.pojo.Tea;

import com.zyt.service.CategoryService;
import com.zyt.service.TeaService;
import com.zyt.service.impl.CategoryServiceImpl;
import com.zyt.service.impl.TeaServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TeaController {
    TeaService teaService =new TeaServiceImpl();
    @RequestMapping("/selectAll")
    public String selectAl(Integer corPage,Model model){
        if (corPage==null){
            corPage=1;
        }
        Integer pageSize=3;
        PageInfo<Tea> pageInfo = teaService.servletAll(corPage,pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "/tealist.jsp";
    }
    @RequestMapping("/updateByIdController")
    public String updateByIdController(Tea tea) {
        teaService.updateById(tea);
        System.out.println(tea);
        return "/selectAll.do";
    }
    @RequestMapping("/selectByCatID")
    public String selectByCatID(Integer id,Model model){
        List<Tea> teaList1 = teaService.selectByCatID(id);
        model.addAttribute("teaList",teaList1);
        return "/tealist.jsp";
    }
    @RequestMapping("/deleteController")
    public String deleteController(Integer id) {
        teaService.deleteById(id);
        return "/selectAll.do";
    }
    @RequestMapping("/allController")
    public String allController(Tea tea) {
        System.out.println(tea);
        teaService.addTea(tea);
        return "/selectAll.do";
    }
    CategoryService categoryService =new CategoryServiceImpl();
    @RequestMapping("/selectById")
    public String selectById(Integer id, Model model) {
        Tea tea = teaService.selectById(id);
        System.out.println(tea);
        model.addAttribute("tea", tea);
        List<Category> categoryList =categoryService.selectAllCategory();
        model.addAttribute("categoryList",categoryList);
        return "/updateTea.jsp";
    }
}
